package com.bdqn.reflect.servlet;

import com.bdqn.reflect.pojo.Book;
import com.bdqn.reflect.util.SimpleBeanConvertor;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * UserServlet
 *
 * @author LILIBO
 * @since 2024/7/2
 */
@WebServlet("/BookServlet")
public class BookServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");

        // 从请求对象中获取页面传递的参数并封装到实体类
        Book book = SimpleBeanConvertor.parseRequest(request, Book.class);

        System.out.println(book);
    }

}
